/**
 * 
 */
package cn.gov.msa.controller;


import java.io.OutputStream;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import cn.gov.msa.collection.LdapService;
import cn.gov.msa.collection.SmsService;
import cn.gov.msa.service.DictService;
import cn.gov.msa.service.FileService;
import cn.gov.msa.service.OrgService;
import cn.gov.msa.util.FileUtil;
import cn.gov.msa.util.InfoObjUtil;
import cn.gov.msa.util.PropertiesTools;
import cn.gov.msa.util.UserUntil;
import cn.gov.msa.util.WebServiceTools;
import cn.msa.gov.model.Org;
import cn.msa.gov.model.UserDetail;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**   
* @Title: ShareController.java 
* @Package cn.gov.msa.controller 
* @Description: TODO(用一句话描述该文件做什么) 
* @author 何宇江  
* @date 2018年2月24日 上午11:44:53 
*/


@RestController
@RequestMapping(value = "/share", produces="text/plain;charset=UTF-8")
public class ShareController {
	
	private static String url  = PropertiesTools.readProperties("gahWS.url");
 
    String methods = PropertiesTools.readProperties("gahWS.methods");
	
	@RequestMapping(value = "/getDictDetail")
	public String getDictDetail(String dictcode,String pitemcode, String itemname) throws Exception {
		String result = "";

		DictService dictService = new DictService();
		result = dictService.GetDictDetail(dictcode,pitemcode,itemname);
		return result;
	}
	
	@RequestMapping(value = "/getDictDetail1")
	public String getDictDetail1(String dictcode, String itemname) throws Exception {
		String result = "{\"result\":0,\"info\":\"none\"}";
		
		DictService dictService = new DictService();
		if(itemname != null && !"".equals(itemname.trim())){
			result = dictService.GetDictDetail(dictcode, null, itemname);
		}
		
		return result;
	}
	
	@RequestMapping(value = "/getOrg")
	public String getOrg(String orgLevel, String orgType, HttpSession session) throws Exception {

//		String data = "{\"hot\":[{\"id\":\"010000\",\"name\":\"上海海事局\"}],\"province\":[{\"id\":\"010000\",\"name\":\"上海海事局\",\"city\":[{\"id\":\"010000\",\"name\":\"上海海事局\"},{\"id\":\"010100\",\"name\":\"吴淞海事局\"},{\"id\":\"010200\",\"name\":\"闵行海事局\"},{\"id\":\"010300\",\"name\":\"黄浦海事局\"},{\"id\":\"010400\",\"name\":\"杨浦海事局\"},{\"id\":\"010500\",\"name\":\"金山海事局\"},{\"id\":\"010600\",\"name\":\"崇明海事局\"},{\"id\":\"010700\",\"name\":\"浦东海事局\"},{\"id\":\"010800\",\"name\":\"宝山海事局\"},{\"id\":\"011000\",\"name\":\"洋山港海事局\"}]},{\"id\":\"020000\",\"name\":\"天津海事局\",\"city\":[{\"id\":\"020000\",\"name\":\"天津海事局\"},{\"id\":\"020100\",\"name\":\"新港海事局\"},{\"id\":\"020200\",\"name\":\"南疆海事局\"},{\"id\":\"020300\",\"name\":\"海河海事局\"},{\"id\":\"020500\",\"name\":\"北疆海事局\"},{\"id\":\"020800\",\"name\":\"东疆海事局\"},{\"id\":\"020900\",\"name\":\"大沽口海事局\"}]},{\"id\":\"030000\",\"name\":\"辽宁海事局\",\"city\":[{\"id\":\"030000\",\"name\":\"辽宁海事局\"},{\"id\":\"030100\",\"name\":\"大连海事局\"},{\"id\":\"030200\",\"name\":\"丹东海事局\"},{\"id\":\"030300\",\"name\":\"锦州海事局\"},{\"id\":\"030400\",\"name\":\"葫芦岛海事局\"},{\"id\":\"150000\",\"name\":\"营口海事局\"}]},{\"id\":\"040000\",\"name\":\"河北海事局\",\"city\":[{\"id\":\"040000\",\"name\":\"河北海事局\"},{\"id\":\"040100\",\"name\":\"秦皇岛海事局\"},{\"id\":\"040200\",\"name\":\"沧州海事局\"},{\"id\":\"040300\",\"name\":\"唐山海事局\"},{\"id\":\"040302\",\"name\":\"曹妃甸海事处\"}]},{\"id\":\"050000\",\"name\":\"山东海事局\",\"city\":[{\"id\":\"050000\",\"name\":\"山东海事局\"},{\"id\":\"050100\",\"name\":\"青岛海事局\"},{\"id\":\"050200\",\"name\":\"济南海事局\"},{\"id\":\"050300\",\"name\":\"威海海事局\"},{\"id\":\"050400\",\"name\":\"日照海事局\"},{\"id\":\"160000\",\"name\":\"烟台海事局\"}]},{\"id\":\"060000\",\"name\":\"江苏海事局\",\"city\":[{\"id\":\"060000\",\"name\":\"江苏海事局\"},{\"id\":\"060100\",\"name\":\"南京海事局\"},{\"id\":\"060200\",\"name\":\"张家港海事局\"},{\"id\":\"060300\",\"name\":\"南通海事局\"},{\"id\":\"060400\",\"name\":\"镇江海事局\"},{\"id\":\"060600\",\"name\":\"江阴海事局\"},{\"id\":\"060700\",\"name\":\"扬州海事局\"},{\"id\":\"060800\",\"name\":\"常州海事局\"},{\"id\":\"060900\",\"name\":\"泰州海事局\"},{\"id\":\"061000\",\"name\":\"常熟海事局\"},{\"id\":\"061100\",\"name\":\"太仓海事局\"},{\"id\":\"061200\",\"name\":\"宜兴海事处\"},{\"id\":\"061300\",\"name\":\"如皋海事局\"},{\"id\":\"061400\",\"name\":\"盐城海事局\"},{\"id\":\"170000\",\"name\":\"连云港海事局\"}]},{\"id\":\"070000\",\"name\":\"浙江海事局\",\"city\":[{\"id\":\"070000\",\"name\":\"浙江海事局\"},{\"id\":\"070100\",\"name\":\"宁波海事局\"},{\"id\":\"070200\",\"name\":\"嘉兴海事局\"},{\"id\":\"070300\",\"name\":\"舟山海事局\"},{\"id\":\"070400\",\"name\":\"温州海事局\"},{\"id\":\"070500\",\"name\":\"台州海事局\"},{\"id\":\"070600\",\"name\":\"杭州海事局\"}]},{\"id\":\"080000\",\"name\":\"福建海事局\",\"city\":[{\"id\":\"080000\",\"name\":\"福建海事局\"},{\"id\":\"080100\",\"name\":\"福州海事局\"},{\"id\":\"080200\",\"name\":\"宁德海事局\"},{\"id\":\"080300\",\"name\":\"莆田海事局\"},{\"id\":\"080400\",\"name\":\"泉州海事局\"},{\"id\":\"080600\",\"name\":\"平潭海事处\"},{\"id\":\"180000\",\"name\":\"厦门海事局\"},{\"id\":\"180100\",\"name\":\"漳州海事局\"}]},{\"id\":\"090000\",\"name\":\"广东海事局\",\"city\":[{\"id\":\"090000\",\"name\":\"广东海事局\"},{\"id\":\"090100\",\"name\":\"广州海事局\"},{\"id\":\"090300\",\"name\":\"珠海海事局\"},{\"id\":\"090400\",\"name\":\"惠州海事局\"},{\"id\":\"090500\",\"name\":\"河源海事局\"},{\"id\":\"090600\",\"name\":\"汕尾海事局\"},{\"id\":\"090700\",\"name\":\"江门海事局\"},{\"id\":\"090800\",\"name\":\"阳江海事局\"},{\"id\":\"090900\",\"name\":\"中山海事局\"},{\"id\":\"091000\",\"name\":\"佛山海事局\"},{\"id\":\"091100\",\"name\":\"肇庆海事局\"},{\"id\":\"091200\",\"name\":\"云浮海事局\"},{\"id\":\"091300\",\"name\":\"清远海事局\"},{\"id\":\"091400\",\"name\":\"韶关海事局\"},{\"id\":\"091500\",\"name\":\"梅州海事局\"},{\"id\":\"091600\",\"name\":\"茂名海事局\"},{\"id\":\"091700\",\"name\":\"潮州海事局\"},{\"id\":\"091800\",\"name\":\"揭阳海事局\"},{\"id\":\"190000\",\"name\":\"汕头海事局\"},{\"id\":\"200000\",\"name\":\"湛江海事局\"}]},{\"id\":\"100000\",\"name\":\"广西海事局\",\"city\":[{\"id\":\"100000\",\"name\":\"广西海事局\"},{\"id\":\"100100\",\"name\":\"南宁海事局\"},{\"id\":\"100200\",\"name\":\"北海海事局\"},{\"id\":\"100300\",\"name\":\"防城港海事局\"},{\"id\":\"100400\",\"name\":\"钦州海事局\"},{\"id\":\"100500\",\"name\":\"柳州海事局\"},{\"id\":\"100600\",\"name\":\"河池海事局\"},{\"id\":\"100700\",\"name\":\"桂林海事局\"},{\"id\":\"100800\",\"name\":\"贵港海事局\"},{\"id\":\"100900\",\"name\":\"梧州海事局\"},{\"id\":\"101000\",\"name\":\"百色海事局\"}]},{\"id\":\"110000\",\"name\":\"海南海事局\",\"city\":[{\"id\":\"110000\",\"name\":\"海南海事局\"},{\"id\":\"110100\",\"name\":\"海口海事局\"},{\"id\":\"110200\",\"name\":\"清澜海事局\"},{\"id\":\"110300\",\"name\":\"三亚海事局\"},{\"id\":\"110400\",\"name\":\"八所海事局\"},{\"id\":\"110500\",\"name\":\"洋浦海事局\"},{\"id\":\"110600\",\"name\":\"三沙海事局\"}]},{\"id\":\"120000\",\"name\":\"长江海事局\",\"city\":[{\"id\":\"120000\",\"name\":\"长江海事局\"},{\"id\":\"120100\",\"name\":\"重庆海事局\"},{\"id\":\"120300\",\"name\":\"重庆万州海事处\"},{\"id\":\"120400\",\"name\":\"重庆涪陵海事处\"},{\"id\":\"120500\",\"name\":\"宜昌海事局\"},{\"id\":\"120600\",\"name\":\"荆州海事局\"},{\"id\":\"120700\",\"name\":\"岳阳海事局\"},{\"id\":\"120800\",\"name\":\"武汉海事局\"},{\"id\":\"120900\",\"name\":\"黄石海事局\"},{\"id\":\"121000\",\"name\":\"九江海事局\"},{\"id\":\"121100\",\"name\":\"安庆海事局\"},{\"id\":\"121200\",\"name\":\"芜湖海事局\"},{\"id\":\"121500\",\"name\":\"三峡海事局\"}]},{\"id\":\"130000\",\"name\":\"黑龙江海事局\",\"city\":[{\"id\":\"130000\",\"name\":\"黑龙江海事局\"},{\"id\":\"130100\",\"name\":\"哈尔滨海事局\"},{\"id\":\"130200\",\"name\":\"佳木斯海事局\"},{\"id\":\"130300\",\"name\":\"黑河海事局\"},{\"id\":\"130400\",\"name\":\"齐齐哈尔海事局\"},{\"id\":\"130500\",\"name\":\"牡丹江海事局\"}]},{\"id\":\"140000\",\"name\":\"深圳海事局\",\"city\":[{\"id\":\"140000\",\"name\":\"深圳海事局\"},{\"id\":\"140100\",\"name\":\"大亚湾海事局\"},{\"id\":\"140200\",\"name\":\"蛇口海事局\"},{\"id\":\"140300\",\"name\":\"盐田海事局\"},{\"id\":\"140400\",\"name\":\"宝安海事局\"},{\"id\":\"140500\",\"name\":\"南山海事局\"},{\"id\":\"140600\",\"name\":\"大铲海事局\"}]}]}";
//		JSONObject jsonResultData = JSONObject.fromObject(data);
		
		String result = "";
		JSONObject param = new JSONObject();
		param.put("orglevel", orgLevel);
		param.put("orgtype", orgType);
		param.put("porgcode", "000000");
		if(session.getAttribute("user") != null){
			param.put("companyid", JSONObject.fromObject(session.getAttribute("user")).optString("companyId"));
		}
		
		String[] parameter = new String[]{"DKS105", param.toString()};
        
        result = WebServiceTools.getDatasByUrl(url, methods, parameter);
	    
        if("1".equals(JSONObject.fromObject(result).getString("result"))){
        	result = JSONObject.fromObject(result).getString("datas").toString();
        }
		return result;
	}
	
	@RequestMapping(value = "/getOrg1")
	public String getOrg1(String orgLevel, String orgType) throws Exception {
		
		String result = "";

		OrgService orgService = new OrgService();
		result = orgService.GetOrgInfo(orgLevel, orgType);
						
		JSONObject jsonResultData = new JSONObject();
		jsonResultData.put("result",1);
		jsonResultData.put("datas",result);
		
		return jsonResultData.toString();
	}

	@RequestMapping(value = "/getOrg2")
	public String getOrg2(String orgLevel, String orgType, HttpSession session) throws Exception {

//		String data = "{\"hot\":[{\"id\":\"010000\",\"name\":\"上海海事局\"}],\"province\":[{\"id\":\"010000\",\"name\":\"上海海事局\",\"city\":[{\"id\":\"010000\",\"name\":\"上海海事局\"},{\"id\":\"010100\",\"name\":\"吴淞海事局\"},{\"id\":\"010200\",\"name\":\"闵行海事局\"},{\"id\":\"010300\",\"name\":\"黄浦海事局\"},{\"id\":\"010400\",\"name\":\"杨浦海事局\"},{\"id\":\"010500\",\"name\":\"金山海事局\"},{\"id\":\"010600\",\"name\":\"崇明海事局\"},{\"id\":\"010700\",\"name\":\"浦东海事局\"},{\"id\":\"010800\",\"name\":\"宝山海事局\"},{\"id\":\"011000\",\"name\":\"洋山港海事局\"}]},{\"id\":\"020000\",\"name\":\"天津海事局\",\"city\":[{\"id\":\"020000\",\"name\":\"天津海事局\"},{\"id\":\"020100\",\"name\":\"新港海事局\"},{\"id\":\"020200\",\"name\":\"南疆海事局\"},{\"id\":\"020300\",\"name\":\"海河海事局\"},{\"id\":\"020500\",\"name\":\"北疆海事局\"},{\"id\":\"020800\",\"name\":\"东疆海事局\"},{\"id\":\"020900\",\"name\":\"大沽口海事局\"}]},{\"id\":\"030000\",\"name\":\"辽宁海事局\",\"city\":[{\"id\":\"030000\",\"name\":\"辽宁海事局\"},{\"id\":\"030100\",\"name\":\"大连海事局\"},{\"id\":\"030200\",\"name\":\"丹东海事局\"},{\"id\":\"030300\",\"name\":\"锦州海事局\"},{\"id\":\"030400\",\"name\":\"葫芦岛海事局\"},{\"id\":\"150000\",\"name\":\"营口海事局\"}]},{\"id\":\"040000\",\"name\":\"河北海事局\",\"city\":[{\"id\":\"040000\",\"name\":\"河北海事局\"},{\"id\":\"040100\",\"name\":\"秦皇岛海事局\"},{\"id\":\"040200\",\"name\":\"沧州海事局\"},{\"id\":\"040300\",\"name\":\"唐山海事局\"},{\"id\":\"040302\",\"name\":\"曹妃甸海事处\"}]},{\"id\":\"050000\",\"name\":\"山东海事局\",\"city\":[{\"id\":\"050000\",\"name\":\"山东海事局\"},{\"id\":\"050100\",\"name\":\"青岛海事局\"},{\"id\":\"050200\",\"name\":\"济南海事局\"},{\"id\":\"050300\",\"name\":\"威海海事局\"},{\"id\":\"050400\",\"name\":\"日照海事局\"},{\"id\":\"160000\",\"name\":\"烟台海事局\"}]},{\"id\":\"060000\",\"name\":\"江苏海事局\",\"city\":[{\"id\":\"060000\",\"name\":\"江苏海事局\"},{\"id\":\"060100\",\"name\":\"南京海事局\"},{\"id\":\"060200\",\"name\":\"张家港海事局\"},{\"id\":\"060300\",\"name\":\"南通海事局\"},{\"id\":\"060400\",\"name\":\"镇江海事局\"},{\"id\":\"060600\",\"name\":\"江阴海事局\"},{\"id\":\"060700\",\"name\":\"扬州海事局\"},{\"id\":\"060800\",\"name\":\"常州海事局\"},{\"id\":\"060900\",\"name\":\"泰州海事局\"},{\"id\":\"061000\",\"name\":\"常熟海事局\"},{\"id\":\"061100\",\"name\":\"太仓海事局\"},{\"id\":\"061200\",\"name\":\"宜兴海事处\"},{\"id\":\"061300\",\"name\":\"如皋海事局\"},{\"id\":\"061400\",\"name\":\"盐城海事局\"},{\"id\":\"170000\",\"name\":\"连云港海事局\"}]},{\"id\":\"070000\",\"name\":\"浙江海事局\",\"city\":[{\"id\":\"070000\",\"name\":\"浙江海事局\"},{\"id\":\"070100\",\"name\":\"宁波海事局\"},{\"id\":\"070200\",\"name\":\"嘉兴海事局\"},{\"id\":\"070300\",\"name\":\"舟山海事局\"},{\"id\":\"070400\",\"name\":\"温州海事局\"},{\"id\":\"070500\",\"name\":\"台州海事局\"},{\"id\":\"070600\",\"name\":\"杭州海事局\"}]},{\"id\":\"080000\",\"name\":\"福建海事局\",\"city\":[{\"id\":\"080000\",\"name\":\"福建海事局\"},{\"id\":\"080100\",\"name\":\"福州海事局\"},{\"id\":\"080200\",\"name\":\"宁德海事局\"},{\"id\":\"080300\",\"name\":\"莆田海事局\"},{\"id\":\"080400\",\"name\":\"泉州海事局\"},{\"id\":\"080600\",\"name\":\"平潭海事处\"},{\"id\":\"180000\",\"name\":\"厦门海事局\"},{\"id\":\"180100\",\"name\":\"漳州海事局\"}]},{\"id\":\"090000\",\"name\":\"广东海事局\",\"city\":[{\"id\":\"090000\",\"name\":\"广东海事局\"},{\"id\":\"090100\",\"name\":\"广州海事局\"},{\"id\":\"090300\",\"name\":\"珠海海事局\"},{\"id\":\"090400\",\"name\":\"惠州海事局\"},{\"id\":\"090500\",\"name\":\"河源海事局\"},{\"id\":\"090600\",\"name\":\"汕尾海事局\"},{\"id\":\"090700\",\"name\":\"江门海事局\"},{\"id\":\"090800\",\"name\":\"阳江海事局\"},{\"id\":\"090900\",\"name\":\"中山海事局\"},{\"id\":\"091000\",\"name\":\"佛山海事局\"},{\"id\":\"091100\",\"name\":\"肇庆海事局\"},{\"id\":\"091200\",\"name\":\"云浮海事局\"},{\"id\":\"091300\",\"name\":\"清远海事局\"},{\"id\":\"091400\",\"name\":\"韶关海事局\"},{\"id\":\"091500\",\"name\":\"梅州海事局\"},{\"id\":\"091600\",\"name\":\"茂名海事局\"},{\"id\":\"091700\",\"name\":\"潮州海事局\"},{\"id\":\"091800\",\"name\":\"揭阳海事局\"},{\"id\":\"190000\",\"name\":\"汕头海事局\"},{\"id\":\"200000\",\"name\":\"湛江海事局\"}]},{\"id\":\"100000\",\"name\":\"广西海事局\",\"city\":[{\"id\":\"100000\",\"name\":\"广西海事局\"},{\"id\":\"100100\",\"name\":\"南宁海事局\"},{\"id\":\"100200\",\"name\":\"北海海事局\"},{\"id\":\"100300\",\"name\":\"防城港海事局\"},{\"id\":\"100400\",\"name\":\"钦州海事局\"},{\"id\":\"100500\",\"name\":\"柳州海事局\"},{\"id\":\"100600\",\"name\":\"河池海事局\"},{\"id\":\"100700\",\"name\":\"桂林海事局\"},{\"id\":\"100800\",\"name\":\"贵港海事局\"},{\"id\":\"100900\",\"name\":\"梧州海事局\"},{\"id\":\"101000\",\"name\":\"百色海事局\"}]},{\"id\":\"110000\",\"name\":\"海南海事局\",\"city\":[{\"id\":\"110000\",\"name\":\"海南海事局\"},{\"id\":\"110100\",\"name\":\"海口海事局\"},{\"id\":\"110200\",\"name\":\"清澜海事局\"},{\"id\":\"110300\",\"name\":\"三亚海事局\"},{\"id\":\"110400\",\"name\":\"八所海事局\"},{\"id\":\"110500\",\"name\":\"洋浦海事局\"},{\"id\":\"110600\",\"name\":\"三沙海事局\"}]},{\"id\":\"120000\",\"name\":\"长江海事局\",\"city\":[{\"id\":\"120000\",\"name\":\"长江海事局\"},{\"id\":\"120100\",\"name\":\"重庆海事局\"},{\"id\":\"120300\",\"name\":\"重庆万州海事处\"},{\"id\":\"120400\",\"name\":\"重庆涪陵海事处\"},{\"id\":\"120500\",\"name\":\"宜昌海事局\"},{\"id\":\"120600\",\"name\":\"荆州海事局\"},{\"id\":\"120700\",\"name\":\"岳阳海事局\"},{\"id\":\"120800\",\"name\":\"武汉海事局\"},{\"id\":\"120900\",\"name\":\"黄石海事局\"},{\"id\":\"121000\",\"name\":\"九江海事局\"},{\"id\":\"121100\",\"name\":\"安庆海事局\"},{\"id\":\"121200\",\"name\":\"芜湖海事局\"},{\"id\":\"121500\",\"name\":\"三峡海事局\"}]},{\"id\":\"130000\",\"name\":\"黑龙江海事局\",\"city\":[{\"id\":\"130000\",\"name\":\"黑龙江海事局\"},{\"id\":\"130100\",\"name\":\"哈尔滨海事局\"},{\"id\":\"130200\",\"name\":\"佳木斯海事局\"},{\"id\":\"130300\",\"name\":\"黑河海事局\"},{\"id\":\"130400\",\"name\":\"齐齐哈尔海事局\"},{\"id\":\"130500\",\"name\":\"牡丹江海事局\"}]},{\"id\":\"140000\",\"name\":\"深圳海事局\",\"city\":[{\"id\":\"140000\",\"name\":\"深圳海事局\"},{\"id\":\"140100\",\"name\":\"大亚湾海事局\"},{\"id\":\"140200\",\"name\":\"蛇口海事局\"},{\"id\":\"140300\",\"name\":\"盐田海事局\"},{\"id\":\"140400\",\"name\":\"宝安海事局\"},{\"id\":\"140500\",\"name\":\"南山海事局\"},{\"id\":\"140600\",\"name\":\"大铲海事局\"}]}]}";
//		JSONObject jsonResultData = JSONObject.fromObject(data);
		
		String result = "";
		JSONObject param = new JSONObject();
		param.put("orglevel", orgLevel);
		param.put("orgtype", orgType);
		param.put("porgcode", "000000");
		if(session.getAttribute("user") != null){
			param.put("companyid", JSONObject.fromObject(session.getAttribute("user")).optString("companyId"));
		}
		
		String[] parameter = new String[]{"DKS105_1", param.toString()};
        
        result = WebServiceTools.getDatasByUrl(url, methods, parameter);
	    
        if("1".equals(JSONObject.fromObject(result).getString("result"))){
        	result = JSONObject.fromObject(result).getString("datas").toString();
        }
		return result;
	}
	
    /**
     * 上传文件
     * @param request
     * @param response
     * @param file 上传的文件，支持多文件
     * @throws Exception
     */
    @RequestMapping("/upload_fileinput.do")
    public String upload_fileinput(HttpServletRequest request,HttpServletResponse response
            ,@RequestParam("file") MultipartFile[] files, String busscode) throws Exception{

    	String result = null;
    	JSONArray param = new JSONArray();
    	
    	if(files.length > 0){
    		for (MultipartFile multipartFile : files) {			
		        String fileName = multipartFile.getOriginalFilename(); 
		        String fileprefixname = fileName.substring(0, fileName.lastIndexOf("."));
		        String filesuffixname = fileName.substring(fileName.lastIndexOf(".") + 1);
		        long filesize = multipartFile.getSize();
		        String filetype = multipartFile.getContentType();
		        
		       	//如果上传的文件格式不在允许范围，允许上传
		        if(!"'jpg', 'png','gif','txt','sql','xlsx','xls','pdf','pptx','docx','doc','jpeg'".contains(filesuffixname))
		        	return null;
		        
		        JSONObject jsonFile = new JSONObject();
		        jsonFile.put("filename", fileprefixname);
		        jsonFile.put("filetype", filetype);
		        jsonFile.put("filesize", filesize);
		        jsonFile.put("filesuffix", filesuffixname);
    					
    			byte[] b = multipartFile.getBytes();
    			String fileStr = FileUtil.bytesToHexString(b);
    			jsonFile.put("content", fileStr);
    			jsonFile.put("busscode", busscode);

    			jsonFile = UserUntil.PutUserMsg(jsonFile);
    			
    			param.add(jsonFile);
			}
    		
    		FileService fileService = new FileService();
    		result = fileService.Upload(param);
    	}
    	else{
    		return null;
            
    	}
    		
    	
    	JSONObject jsonResult = JSONObject.fromObject(result);
    	if(1 == jsonResult.getInt("result"))
    		return jsonResult.toString();
    	else 
    		return null;
    }
    
    /**
     * 文件下载
     */
	@RequestMapping("/downFiles")
	public void downFiles(HttpServletResponse response, String filename, String fileid) {
		try {

			byte[] b = null;
			filename = new String(filename.getBytes(), "ISO-8859-1");
			response.setHeader("Content-Disposition",
					"attachment; filename=" + filename);
			
//			File file = new File("D://述职报告--何宇江.pptx");
//			
//			b = FileUtil.fileTobyte(file);

    		JSONObject jsonParams = new JSONObject();
    		jsonParams.put("fileid", fileid);
    		
    		FileService fileService = new FileService();
    		String result = fileService.Down(jsonParams);
    		
    		JSONObject jsonResult = JSONObject.fromObject(result);
    		System.err.println(jsonResult.getInt("result"));
    		if(1 == jsonResult.getInt("result")){
    			String content = jsonResult.getString("datas");
    			
    			b = FileUtil.hexStringToBytes(content);
    		
				OutputStream out = response.getOutputStream();
				out.write(b);
				out.close();
    		}
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

    
	@RequestMapping(value = "/getwaterway")
	public String getWaterway(String orgcode) throws Exception {

		JSONObject param = new JSONObject();
		param.put("orgcode", orgcode);
		
        String[] parameter = new String[]{"DKS126", param.toString()};
        
        String result = WebServiceTools.getDatasByUrl(url, methods, parameter);
        
    	
        return result;  
	}
	
	@RequestMapping(value = "/getmark")
	public String getMark(String waterwaycode) throws Exception {

		JSONObject param = new JSONObject();
		param.put("waterwaycode", waterwaycode);
		
        String[] parameter = new String[]{"DKS127", param.toString()};
        
        String result = WebServiceTools.getDatasByUrl(url, methods, parameter);
        
    	
        return result;  
	}


	@RequestMapping(value = "/getshiplist", method = RequestMethod.POST)
	public String getShipList(@RequestBody JSONObject param) throws Exception {
		String result = "{'total': 0, rows: []}";
		if(!param.optString("SHIP_NAME_CN").equals("-")){
	        String[] parameter = new String[]{"FHS101", param.toString()};       
	        result = WebServiceTools.getDatasByUrl(url, methods, parameter);
	
	        JSONObject jsonResult = JSONObject.fromObject(result);
	    	result = jsonResult.getJSONObject("datas").toString();    	
		}
        return result;  
    } 
	
	@RequestMapping(value = "/check", method = RequestMethod.POST)
	public String check(@RequestBody JSONObject param) throws Exception {
        String[] parameter = new String[]{"FHS103", param.toString()};       
        String result = WebServiceTools.getDatasByUrl(url, methods, parameter);       
        return result;  
    } 

	@RequestMapping(value = "/getberthlist", method = RequestMethod.POST)
	public String getBerthList(@RequestBody JSONObject param) throws Exception {
        String[] parameter = new String[]{"FHS102", param.toString()};       
        String result = WebServiceTools.getDatasByUrl(url, methods, parameter);

        JSONObject jsonResult = JSONObject.fromObject(result);
    	result = jsonResult.getString("datas");
        
        return result;  
    } 

	@RequestMapping(value = "/getportlist", method = RequestMethod.POST)
	public String getPortList(@RequestBody JSONObject param) throws Exception {
        String[] parameter = new String[]{"FHS110", param.toString()};       
        String result = WebServiceTools.getDatasByUrl(url, methods, parameter);
        
        return result;  
    }
	
	@RequestMapping(value = "/getverify", method = RequestMethod.POST)
	public String getVerify(@RequestBody JSONObject param) throws Exception {
        String[] parameter = new String[]{"FHS104", param.toString()};       
        String result = WebServiceTools.getDatasByUrl(url, methods, parameter);
        
        return result;  
    } 
	

	@RequestMapping(value = "/getorginfo", method = RequestMethod.POST)
	public String getOrgInfo(HttpSession session) throws Exception {
		JSONObject json = new JSONObject();
		String result = "0";
		String info = InfoObjUtil.Error_NODATA;
		
		try {
			String userid= session.getAttribute("userid").toString();
			
			System.err.println("userid>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" + userid);
				
			Org org = LdapService.getOrgDetail(userid);
			
			if(null != org){
				result = "1";
				info = InfoObjUtil.Success_select_OK;
				json.put("datas", JSONObject.fromObject(org));
			}
		} catch (Exception e) {
			result = "2";
			info = InfoObjUtil.Exption_msg;
			
			e.printStackTrace();
		}
		
		json.put("result", result);
		json.put("info", info);
        
        return json.toString();  
    } 

	@RequestMapping(value = "/right", method = RequestMethod.POST)
	public String right( HttpSession session, HttpServletRequest httpRequest) throws Exception {
		JSONObject json = new JSONObject();
		String result = "0";
		String info = InfoObjUtil.Error_save_no;
		
		try {
			String userid= session.getAttribute("userid").toString();
				
			String right = LdapService.right(userid);
			
			if(null != right){
				result = "1";
				info = InfoObjUtil.Success_save_OK;
				json.put("datas", right);
			}
		} catch (Exception e) {
			result = "2";
			info = InfoObjUtil.Exption_msg;
			
			e.printStackTrace();
		}
		
		json.put("result", result);
		json.put("info", info);
        
        return json.toString();  
    } 
	
	
	@RequestMapping(value = "/getcompanyorg")
	public String getCompanyOrg(HttpSession session) throws Exception {
		
		UserDetail userDetail4A = (UserDetail)session.getAttribute("user");	
		
		JSONObject param = new JSONObject();
		param.put("companyid", userDetail4A.getCompanyId());

        String[] parameter = new String[]{"DKS207", param.toString()};       
        String result = WebServiceTools.getDatasByUrl(url, methods, parameter);
        
        return result;
	}
	
	@RequestMapping(value = "/sendMessage")
	public String sendMessage(@RequestBody JSONObject param) throws Exception {
		
		String result = SmsService.sendSingleMessage(param.getString("phone"), param.getString("message"));
        return result;
	}
	
	@RequestMapping(value = "/addLocalShip", method = RequestMethod.POST)
	public String addLocalShip(@RequestBody JSONObject param, HttpSession session) throws Exception {
		
		UserDetail userDetail = (UserDetail)session.getAttribute("user");	
		
		param.put("syscreatedby", userDetail.getUserId());
		param.put("syscreatedbyname", userDetail.getUserName());
		param.put("sysorg", userDetail.getCompanyId());
		param.put("sysorgname", userDetail.getCompany());

        String[] parameter = new String[]{"FHS111", param.toString()};
        String result = WebServiceTools.getDatasByUrl(url, methods, parameter);
        
        return result;
	}
	
	@RequestMapping(value = "/getLocalShip", method = RequestMethod.POST)
	public String getLocalShip(@RequestBody JSONObject param, HttpSession session) throws Exception {
		
		UserDetail userDetail = (UserDetail)session.getAttribute("user");	
		
		param.put("sysorg", userDetail.getCompanyId());

        String[] parameter = new String[]{"FHS112", param.toString()};
        String result = WebServiceTools.getDatasByUrl(url, methods, parameter);
        
        return result;
	}
	
}
